﻿Imports EguSoc_Dll

Public Class FES_Socios
    Private TA_socios As New Socios_TableAdapter
    Private TA_Sobre As New Cabecera_SobreTableAdapter
    Private TA_Tipo_Socio As New DSEATableAdapters.Tipo_SocioTableAdapter

    Private Tipo_Socio As String
    Private Socio As String

    Private Sub FEA_Socios_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            TA_Tipo_Socio.Fill(DSEA.Tipo_Socio)

            If Tipo_Socio = "4" Then
                TA_socios.Fill(DSEA.Socios)
                TA_Sobre.FillByCompleto(DSEA.Cabecera_Sobre)
            Else
                TA_socios.FillBySocio(DSEA.Socios, Socio)
                TA_Sobre.FillByTipo_Socio_Sobre(DSEA.Cabecera_Sobre, Socio, "D")
                If DSEA.Socios.Count > 0 Then
                    PermisosComboBox.Enabled = False
                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub SociosBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SociosBindingNavigatorSaveItem.Click
        Try
            Call Grabar()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripExit.Click
        Try
            If DSEA.HasChanges Then
                Select Case MessageBox.Show("¿Desea guardar antes de salir?", "Txerri Aska", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information)
                    Case vbYes
                        Grabar()
                        Me.Close()
                    Case vbNo
                        Me.Close()
                    Case Else
                        Exit Sub
                End Select
            Else
                Me.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Grabar()
        Try
            If Me.Validate Then
                Me.SociosBindingSource.EndEdit()
                TA_socios.Grabar(TryCast(SociosBindingSource.Current.ROW, DSEA.SociosRow))
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BtnPin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPin.Click
        Try
            Dim Pin_teclado As New JanuControls.TecladoNumerico
            Pin_teclado.Pass = True

            Pin_teclado.ShowDialog()

            If Pin_teclado.Respuesta Then
                TA_socios.Establecer_Pin(TryCast(SociosBindingSource.Current.Row, DSEA.SociosRow), Pin_teclado.Texto)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub PermisosComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            PermisosComboBox.EndUpdate()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub FotoPictureBox_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FotoPictureBox.Click
        Try
            If OFDImagen.ShowDialog = DialogResult.OK Then
                Dim imagen As New Bitmap(New Bitmap(OFDImagen.FileName), FotoPictureBox.Width, FotoPictureBox.Height)
                FotoPictureBox.Image = imagen
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Public Sub New(ByVal auxSocio As String, ByVal auxTipo_Socio As String)
        Tipo_Socio = auxTipo_Socio
        Socio = auxSocio
        InitializeComponent()
    End Sub

    Private Sub BtnPagar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPagar.Click
        Try
            For Each Dr As DataGridViewRow In DGWSobres.SelectedRows
                Dim DR_Aux As DSEA.Cabecera_SobreRow = TryCast(Dr.DataBoundItem.Row, DSEA.Cabecera_SobreRow)

                DR_Aux.Pagar()

                Cabecera_SobreBindingSource.EndEdit()
                TA_Sobre.Guardar(DR_Aux)
            Next

            TA_Sobre.FillByTipo_Socio_Sobre(DSEA.Cabecera_Sobre, Socio, "D")

        Catch ex As Exception
            Console.Write(ex.Message)
        End Try
    End Sub
End Class